package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    // 查询今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest() {
        return makeFriendManager.findTodayBest();
    }

    // 查询推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return makeFriendManager.findRecommendUserVoByPage(pageNum, pageSize);
    }

    // 佳人详情
    @GetMapping("/tanhua/{jiarenId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long jiarenId) {
        return makeFriendManager.findPersonalInfo(jiarenId);
    }


    // 判断你是否喜欢对方
    @GetMapping("/users/{jiarenId}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable Long jiarenId){
        return ResponseEntity.ok(false); // todo  后期项目实战需要完善此处代码
    }


    // 查询历史访客
    @GetMapping("/movements/visitors")
    public ResponseEntity visitors(){
        return makeFriendManager.visitors();
    }

    // 上报地理位置
    @PostMapping("/baidu/location")
    public void saveLocation(@RequestBody Map<String,String> param){
        System.out.println("用户上传地理坐标："+param);

        // 必须用包装类接收
        Double latitude = Double.parseDouble(param.get("latitude"));
        Double longitude = Double.parseDouble(param.get("longitude"));
        String addrStr = param.get("addrStr");
        // 调用manager
        makeFriendManager.saveLocation(latitude,longitude,addrStr);
    }


    // 搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNearUser(String gender,Long distance){
        // 调用manager
        return makeFriendManager.searchNearUser(gender,distance);
    }

    // 查看对方的陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam(value = "userId") Long jiarenId){
        // 调用manager
        return makeFriendManager.strangerQuestions(jiarenId);
    }
}
